/* 解决js计算精度问题 */
import { Decimal } from 'decimal.js';//引入
let calObj = null
class Cal {
    jia(num1,num2) {
		num1 = num1 || 0
		num2 = num2 || 0
		
        return new Decimal(num1).add(new Decimal(num2))
    }
    jian(num1,num2) {
		num1 = num1 || 0
		num2 = num2 || 0
        return new Decimal(num1).sub(new Decimal(num2))
    }
    cheng(num1,num2) {
		num1 = num1 || 0
		num2 = num2 || 0
        return new Decimal(num1).mul(new Decimal(num2))
    }
    chu(num1,num2) {
		num1 = num1 || 0
		num2 = num2 || 1
        return new Decimal(num1).div(new Decimal(num2))
    }
}
function getCal(){
	if(calObj){
		return calObj
	}
	calObj = new Cal()
	return calObj
}
export const cal = getCal();

/* 调用方法及返回值 */
/*
import { cal } from '@/utils/cal.js';

let a =0.88;
let b = 0.99;

result = cal.jia(a,b).toNumber() //加
result = cal.jian(a,b).toNumber() //减
result = cal.cheng(a,b).toNumber() //乘
result = cal.chu(a,b).toNumber() //除

 */
